package com.ruoyi.business.service.impl;

import java.util.List;

import com.ruoyi.business.domain.enums.GradeLevelEnum;
import com.ruoyi.business.domain.enums.HeightWeightGradeEnum;
import com.ruoyi.business.domain.enums.ProjectTypeEnum;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.business.mapper.ProjectStandardMapper;
import com.ruoyi.business.domain.ProjectStandard;
import com.ruoyi.business.service.IProjectStandardService;
import org.springframework.util.ObjectUtils;

/**
 * 项目标准Service业务层处理
 * 
 * @author lcz
 * @date 2025-02-23
 */
@Service
public class ProjectStandardServiceImpl implements IProjectStandardService 
{
    @Autowired
    private ProjectStandardMapper projectStandardMapper;

    /**
     * 查询项目标准
     * 
     * @param id 项目标准主键
     * @return 项目标准
     */
    @Override
    public ProjectStandard selectProjectStandardById(Long id)
    {
        return projectStandardMapper.selectProjectStandardById(id);
    }

    /**
     * 查询项目标准列表
     * 
     * @param projectStandard 项目标准
     * @return 项目标准
     */
    @Override
    public List<ProjectStandard> selectProjectStandardList(ProjectStandard projectStandard)
    {
        return projectStandardMapper.selectProjectStandardList(projectStandard);
    }

    /**
     * 新增项目标准
     * 
     * @param projectStandard 项目标准
     * @return 结果
     */
    @Override
    public int insertProjectStandard(ProjectStandard projectStandard)
    {
        projectStandard.setCreateTime(DateUtils.getNowDate());
        if (projectStandard.getProjectType().equals(ProjectTypeEnum.HEIGHT.getCode())){
            projectStandard.setGradeName(HeightWeightGradeEnum.getGrade(projectStandard.getGradeId()).getValue());
        }else {
            projectStandard.setGradeName(GradeLevelEnum.getGrade(projectStandard.getGradeId()).getValue());
        }
        return projectStandardMapper.insertProjectStandard(projectStandard);
    }

    /**
     * 修改项目标准
     * 
     * @param projectStandard 项目标准
     * @return 结果
     */
    @Override
    public int updateProjectStandard(ProjectStandard projectStandard)
    {
        if (!ObjectUtils.isEmpty(projectStandard.getGradeId())) {
            if (projectStandard.getProjectType().equals(ProjectTypeEnum.HEIGHT.getCode())){
                projectStandard.setGradeName(HeightWeightGradeEnum.getGrade(projectStandard.getGradeId()).getValue());
            }else {
                projectStandard.setGradeName(GradeLevelEnum.getGrade(projectStandard.getGradeId()).getValue());
            }
        }
        projectStandard.setUpdateTime(DateUtils.getNowDate());
        return projectStandardMapper.updateProjectStandard(projectStandard);
    }

    /**
     * 批量删除项目标准
     * 
     * @param ids 需要删除的项目标准主键
     * @return 结果
     */
    @Override
    public int deleteProjectStandardByIds(Long[] ids)
    {
        return projectStandardMapper.deleteProjectStandardByIds(ids);
    }

    /**
     * 删除项目标准信息
     * 
     * @param id 项目标准主键
     * @return 结果
     */
    @Override
    public int deleteProjectStandardById(Long id)
    {
        return projectStandardMapper.deleteProjectStandardById(id);
    }
}
